package com.koron.css2.newProjectCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.query.PjTimePostponeQueryBean;
import com.koron.css2.newProjectCenter.mapper.PjProcessNodeTimePostponeMapper;
import com.koron.css2.newProjectCenter.vo.PjProcessNodeTimePostponeListVO;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
import java.util.Map;

/**
 * 用户工程2.1 延期查询列表
 * @author admin
 * @version 2.1
 * @since 2021-06-08
 *
 */
public class PjTimePostponeList implements ServerInterface{

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			//将入参转换为QueryBean
			PjTimePostponeQueryBean queryBean = JsonUtils.objectToPojo(req.getData(), PjTimePostponeQueryBean.class);
			
			//获取Mapper实例
			PjProcessNodeTimePostponeMapper mapper = factory.getMapper(PjProcessNodeTimePostponeMapper.class);
			//设置分页参数
			PageHelper.startPage(queryBean.getPage(), queryBean.getPageCount());
			//执行SQL
			List<PjProcessNodeTimePostponeListVO> list = mapper.selectList(queryBean);
			//获取工程类型数据字典
			Map<String, String> PPT = Tools.mapDicByCode(factory, "PPT");
			for(PjProcessNodeTimePostponeListVO bean : list) {
				bean.setPjTypeName(PPT.get(bean.getPjType().toString()));
				if(StringUtils.isNotBlank(bean.getProcessState())) {
					bean.setProcessState(Tools.transProcessStatus(bean.getProcessState()));
				}
			}
			//输出分页结果
			MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
			info.setData(new PageInfo<>(list));
			return info;
		}catch(Exception e){
			logger.error("工程延期列表查询失败"+e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "工程延期查询失败", null);
		}
	}

}
